package org.picommo.tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.picommo.common.Direction;
import org.picommo.common.Frame;
import org.picommo.common.Vec2;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

public class DatabaseTests {
	
	ObjectContainer db;
	
	@Before
	public void setup() {
		db = Db4o.openFile("test.objects");
		
	}
	
	
	@Test
	public void queryByExample() {
		Frame f1 = new Frame(new Vec2(1,1), Direction.north);
		Frame f2 = new Frame(new Vec2(2,2), Direction.north);
		
		db.store(f1);
		db.store(f2);
		
		Frame exampleFrame = new Frame(null, Direction.north);
		ObjectSet<Frame> set = db.queryByExample(exampleFrame);
		assertTrue(set.size() == 2);
	}
	
	
	@After
	public void cleanUp() {
		
		ObjectSet<Frame> set = db.query(Frame.class);
		assertTrue(set.size() == 2);
		
		for(Frame f : set) {
			db.delete(f);
		}
		
		db.close();
	}

}
